﻿package org.hsl.haxe;
import org.hsl.haxe.ISlotList;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.TranslatingSignaler;
class Facade {
	private static inline var SIGNALER_SUFFIX:String = "Signaler";
	private static inline var SLOT_LIST_SUFFIX:String = "SlotList";
	public function new():Void {
	}
	public static function setupNullSignalType<D>(dispatcher:IDispatcher, signalType:String, ?signalDataType:Class<D>):Void {
		setField(dispatcher, signalType, SLOT_LIST_SUFFIX, new NullSlotList<D>());
	}
	public static function setupSignalType<D>(dispatcher:IDispatcher, signalType:String, ?signalDataType:Class<D>):Void {
		var signaler:ISignaler<D> = new CommonSignaler<D>(dispatcher);
		setField(dispatcher, signalType, SIGNALER_SUFFIX, signaler);
		setField(dispatcher, signalType, SLOT_LIST_SUFFIX, new CommonSlotList<D>(signaler.advanced.connectToSlotList));
	}
	#if flash9
	public static function setupTranslatedSignalType<D>(dispatcher:IDispatcher, signalType:String, ?signalDataType:Class<D>, nativeDispatcher:flash.events.EventDispatcher, nativeEventType:String, ?translator:ITranslator<D>):Void {
		var signaler:TranslatingSignaler<D> = new TranslatingSignaler(dispatcher, translator);
		setField(dispatcher, signalType, SIGNALER_SUFFIX, signaler);
		setField(dispatcher, signalType, SLOT_LIST_SUFFIX, new CommonSlotList<D>(signaler.advanced.connectToSlotList));
		nativeDispatcher.addEventListener(nativeEventType, signaler.dispatchNative);
	}
	#end
	private static inline function setField<D>(dispatcher:D, signalType:String, suffix:String, value:Dynamic):Void {
		Reflect.setField(dispatcher, signalType + suffix, value);
	}
}